package com.web.controller;

import com.web.entity.ResponseResult;
import com.web.service.StudentService;
import com.web.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/RemoveStudentById")
public class RemoveStudentById extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置请求编码
        request.setCharacterEncoding("UTF-8");
        //设置响应编码
        response.setCharacterEncoding("UTF-8");
        //设置响应类型
        response.setContentType("application/json;charset=UTF-8");
        //获取请求参数
        String id = request.getParameter("id");
        //创造业务逻辑层对象
        StudentService studentService = new StudentServiceImpl();
        //判断id是否为空
        if (id != null){
            //判断sql语句是否执行成功
            if (studentService.removeStudentById(Integer.parseInt(id))){
                response.getWriter().write("删除成功！");
            }else {
                response.getWriter().write("删除失败！");
            }
        }else {
            response.getWriter().write("信息不完整！");
        }
    }
}
